<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
     <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.1.0.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
		// 전체 회원 목록에서  특정회원 탈퇴버튼 누르면, 해당 회원을 탈퇴시킴
		$(":input[name=dropoutMember]").click(function(){
			if(confirm("회원을 탈퇴시키시겠습니까?")){
				var id=$(this).next().val();
				location.href="dropoutMemberByAdmin.ju?id="+id;
			} //if
		}); //click
		
		// 전체 회원목록에서 id 로 특정회원을 검색해서 탈퇴시킴
		$("#findMemberById").keydown(function(event){
			if(event.keyCode==13){
			//	alert("나와");
				var id=$("#findMemberById").val();
				if(id==""){
					alert("검색할 ID를 입력해주세요");
					return false;
				}
			} //keydown
		});
		
		
		$("#findMemberByIdBtn").click(function(){
				$("#memberControlArea").empty();
				
			var id=$("#findMemberById").val();
			if(id==""){
				alert("검색할 ID를 입력해주세요");
				return false;
			}
			
			// id 로 검색한 회원정보를 ajax 로 불러와서 탈퇴버튼을 만들어줌
			$.ajax({
				type:"POST",
				url:"findId.ju",
				data:"id="+id,
				success:function(data){
				//	alert(data);
				$("#memberControlArea").empty();
					if(data!=false){
						$("#memberControlArea").html("<br><table class='table table-striped table-hover'><tr><td>"+data.id+"</td><td>"
								+data.nickname+"</td><td>"+data.email+"</td><td>"+data.grade+"</td><td><input type='button' name='dropoutMember' value='회원강퇴'><input type='hidden' name='id' value="+data.id+"></td></tr></table>");
					}else{
						$("#memberControlArea").append(id+" 는(은) 사용자가 없습니다");
					}
				} //success
			}); //ajax
		}); //click
		$("#memberControlArea").on("click",":input[name=dropoutMember]",function(){
			//alert("실행되라");
			if(confirm("회원을 탈퇴시키시겠습니까?")){
				var id=$(this).next().val();
				location.href="dropoutMemberByAdmin.ju?id="+id;
			} //if
		});
	});//ready
</script>
</head>
<body>

<form method="post" id="memberControl">
	<table class="table table-striped table-hover">
	<caption class="capt">회원 목록</caption>
<thead>
  <tr>
   <th class="id">아이디</th>
   <th class="nickname">닉네임</th>
  <th class="email">이메일</th>
   <th class="grade">회원등급</th>
   <th >회원강퇴</th>
   </tr>
 </thead>
 <tbody id="tbody">
 <c:forEach items="${requestScope.mvo.list}" var="list">
 <tr height="45" align="center"
 ><td>${list.id }</td>
 <td>${list.nickname }</td>
 <td>${list.email }</td>
 <td>${list.grade }</td>
 <td><input type="button" name="dropoutMember" value="회원강퇴">
 <input type="hidden" name="id" value="${list.id }"></td>
 </tr>
</c:forEach>
</tbody>
<tfoot >
<tr height="45" align="center">
<td>
<!-- 현재그룹의 시작페이지번호-페이지 그룹당 페이지 수 하여 이동 -->
<c:choose>
<c:when test="${requestScope.mvo.pagingBean.previousPageGroup}">
<a href="${initParam.root}getAllMemberList.ju?nowPage=${requestScope.mvo.pagingBean.startPageOfPageGroup - requestScope.mvo.pagingBean.numberOfPageGroup}">◀</a>
</c:when>
</c:choose>
</td>
<td>
<!-- 현재 그룹의 페이지번호 출력 및 게시물보기 링크 -->
<c:forEach var= "i" 
begin="${requestScope.mvo.pagingBean.startPageOfPageGroup}" end="${requestScope.mvo.pagingBean.endPageOfPageGroup}">
<a href="${initParam.root}getAllMemberList.ju?nowPage=${i}">${i}</a>
<c:if test="${i !=requestScope.mvo.pagingBean.endPageOfPageGroup}">| 
		</c:if>
</c:forEach>
</td>

<td>

<!-- 현재그룹의 마지막페이지번호 +1로 이동 -->
<c:choose>
<c:when test="${requestScope.mvo.pagingBean.nextPageGroup == 'true'}">
<a href="${initParam.root}getAllMemberList.ju?nowPage=${requestScope.mvo.pagingBean.endPageOfPageGroup +1}">▶</a>
</c:when>
</c:choose>
</table>
</form>
<br>
<div align="center">
회원 ID <input type="text" id="findMemberById" name="id">
<input type="button" value="검색" id="findMemberByIdBtn"><br>
</div><br>
<span id="memberControlArea" align="center"></span>
</body><br>
</html>